<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 java.util.Calendar"%>

<chiptrack:checkLogon sourcePage="/salesReport.do?action=shippingreport" />

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<%
    String baseProductId    = request.getParameter("product");
    String holdType         = request.getParameter("holdtype");
    String categoryType     = request.getParameter("category");

    String[] hold           = {"",""};
    String[] category       = {"",""};

    if( baseProductId == null || ( baseProductId != null && baseProductId.trim().length() == 0 ) )
    {
        baseProductId = "0";
    }
    if( holdType != null && holdType.equalsIgnoreCase("WITHHOLD") )
    {
        hold[0] = "checked";
    }
    else
    {
        hold[1] = "checked";
    }
    if( categoryType != null && categoryType.equalsIgnoreCase("REQUESTED") )
    {
        category[0] = "checked";
    }
    else
    {
        category[1] = "checked";
    }
%>

<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel=stylesheet>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>

<script>
	function submitAgedBacklogForm()
	{
		var d = new Date();
		var day = d.getDate();
		var month = d.getMonth()+1;
		var year = d.getFullYear();
		var hour = d.getHours();
		var min = d.getMinutes();
		var sec = d.getSeconds();

		var reportName = document.agedBacklogForm.reportname.value;
		var defaultPrompt = day+"/"+month+"/"+year+":"+hour+":"+min+":"+sec;

		var customerType    = "";
		var customerId      = "";
		var holdtype        = "";

		if( document.agedBacklogForm.product.options[document.agedBacklogForm.product.selectedIndex].value == '')
        {
            var pa=document.getElementById("errors");
            pa.innerHTML = "Please select valid Base Product";
            return false;
        }

		if( document.agedBacklogForm.holdtype[0].checked )
		{
			holdtype = "WITHHOLD";
		}
		else if( document.agedBacklogForm.holdtype[1].checked )
		{
			holdtype = "WITHOUTHOLD";
		}
		var category="";
		for (counter = 0; counter < document.agedBacklogForm.category.length; counter++)
		{
			if ( document.agedBacklogForm.category[ counter ].checked )
			{
			category = document.agedBacklogForm.category[counter].value;
			}
		}
		if (document.agedBacklogForm.product.value=='')
		{
			document.agedBacklogForm.prompt0.value='0';
		}
		else
		{
			document.agedBacklogForm.prompt0.value = document.agedBacklogForm.product.value;
		}
		document.agedBacklogForm.prompt1.value = holdtype;
		document.agedBacklogForm.prompt2.value = category;
		document.agedBacklogForm.prompt3.value = defaultPrompt;

		if( document.agedBacklogForm.product.value != "" )
		{
			document.agedBacklogForm.action="<%=chipTracContext%>/jsp/report.jsp?nameReport=Sales/SummaryReports/Aged_Backlog_Report.rpt";
			document.agedBacklogForm.submit();
			return true;
		}
		return false;
	}

    function chkQuarter()
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = "";
        if( document.shipReport.chkbyMonth.checked == true )
        {
            if( document.shipReport.quarter.value == 'All' )
            {
                pa.innerHTML = "<li> Please select Quarter other than 'All' ";
                return false
            }
        }
        return true;
    }

    function clearErrors()
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = "";
    }

    function selectBaseProduct()
    {
        var productId = document.agedBacklogForm.product.value;
        if( document.agedBacklogForm.product.value=='')
        {
            document.agedBacklogForm.action="<%=chipTracContext%>/salesReport.do?action=agedbacklogreport";
            document.agedBacklogForm.submit();
            return;
        }
        return;
    }
    function disableProductDropDownBox()
    {
        if( document.agedBacklogForm.detailorsummary[0].checked )
        {
            document.agedBacklogForm.mfgproducts.disabled = false;
        }
        else
        {
            document.agedBacklogForm.mfgproducts.disabled = true;
        }
    }

    function disableDropDownBox()
    {
        if( document.agedBacklogForm.searchType[0].checked )
        {
            if ( document.agedBacklogForm.product.disabled == true )
            {
                document.agedBacklogForm.product.disabled = false;
            }
            if ( document.agedBacklogForm.mfgproducts.disabled == true )
            {
                document.agedBacklogForm.mfgproducts.disabled = false;
            }
            if ( document.agedBacklogForm.detailorsummary[0].disabled == true )
            {
                document.agedBacklogForm.detailorsummary[0].disabled = false
            }
            if ( document.agedBacklogForm.detailorsummary[1].disabled == true )
            {
                document.agedBacklogForm.detailorsummary[1].disabled = false
            }
            document.agedBacklogForm.customers.value = '0';
            document.agedBacklogForm.customers.disabled = true;
            document.agedBacklogForm.enduser.value = '0';
            document.agedBacklogForm.enduser.disabled = true;
        }
        else if( document.agedBacklogForm.searchType[1].checked )
        {
            if ( document.agedBacklogForm.customers.disabled == true )
            {
                 document.agedBacklogForm.customers.disabled = false;
            }
            document.agedBacklogForm.detailorsummary[0].disabled = true
            document.agedBacklogForm.detailorsummary[1].disabled = true
            document.agedBacklogForm.product.value = '0';
            document.agedBacklogForm.product.disabled = true;
            document.agedBacklogForm.mfgproducts.value = '0';
            document.agedBacklogForm.mfgproducts.disabled = true;
            document.agedBacklogForm.enduser.value = '0';
            document.agedBacklogForm.enduser.disabled = true;
        }
        else
        {
            if ( document.agedBacklogForm.enduser.disabled == true )
            {
                document.agedBacklogForm.enduser.disabled = false;
            }
            document.agedBacklogForm.detailorsummary[0].disabled = true
            document.agedBacklogForm.detailorsummary[1].disabled = true
            document.agedBacklogForm.product.value = '0';
            document.agedBacklogForm.product.disabled = true;
            document.agedBacklogForm.mfgproducts.value = '0';
            document.agedBacklogForm.mfgproducts.disabled = true;
            document.agedBacklogForm.customers.value = '0';
            document.agedBacklogForm.customers.disabled = true;
        }
    }
</script>
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onload="">
	<!-- Top Header Start-->
	<%@ include file="/jsp/includes/header.jsp" %>
	<!-- Top Header End-->

			<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
				<TR>
					<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
						<!-- Side Navigation start -->
						<%@ include file="/jsp/sales/sales_report_menu.jsp" %>
						<!-- end of the side navigations -->
					</td>
					<TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
					<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
					<TD bgcolor="#ffffff">
						<form name="agedBacklogForm" method="post">
						<input type="hidden" name="prompt0">
						<input type="hidden" name="prompt1">
						<input type="hidden" name="prompt2">
						<input type="hidden" name="prompt3">
						<input type="hidden" name="prompt4">
						<input type="hidden" name="prompt5">
						<input type="hidden" name="prompt6">
						<input type="hidden" name="prompt7">
						<input type="hidden" name="prompt8">
						<input type="hidden" name="prompt9">
						<input type="hidden" name="prompt10">
						<input type="hidden" name="reportname" value="<%=request.getParameter("reportname")%>">
					</TD>
					<TD valign="top" width="100%">
						<table border="0" width="100%" align="center">
							<tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
							<tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
							<tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
							<tr>
								<TD width="100%" COLSPAN="6">
									<TABLE width="100%" align="right" border="0">
										<TR>
											<TD width="35%">&nbsp;</TD>
											<TD width="55%"  class="NArialW">Aged Backlog Report</TD>
											<TD width="10%">&nbsp;</TD>
										</TR>
									</TABLE>
								</TD>
							</tr>
							<%--<tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr> --%>
							<tr>
								<td width="15%">&nbsp;</td>
								<td width="85%" colspan="5" align="left">
									&nbsp;
								</td>
							</tr>
							<TR>
								<TD width="100%" COLSPAN="6">
									<TABLE width="100%" align=right border="0">
										<TR><TD colSpan="6">&nbsp;</TD></TR>
										<%--<TR>
											<TD width="5%">&nbsp;</TD>
											 <TD width="20%">&nbsp;</TD>
											<TD colSpan="4" class=NArialL>
												<input type="radio" name="searchType" value="PRODUCT" checked onclick = "javascript:disableDropDownBox();selectBaseProduct();">&nbsp;&nbsp;By Product&nbsp;&nbsp;&nbsp;&nbsp;
												<input type="radio" name="searchType" value="CUSTOMER" onclick = "javascript:disableDropDownBox();">&nbsp;&nbsp;By Customer&nbsp;&nbsp;&nbsp;&nbsp;
												<input type="radio" name="searchType" value="ENDCUSTOMER" onclick = "javascript:disableDropDownBox();" >&nbsp;&nbsp;By End Customer&nbsp;&nbsp;
											</TD>
										</TR> --%>
										<TR>
											<td width="15%">&nbsp;</td>
											<td width="85%" colspan="5" align="left">
												&nbsp;<b><font face="Verdana" size="-5" align="center" color="#ff0000" id="errors"></font><b>
											</td>
										</TR>
										<TR><TD colSpan="6"><IMG height=8 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD></TR>
										<TR>
											<TD width="25%">&nbsp;</TD>
											<TD width="25%" class=NArialL valign="top" align="center">Base Products</TD>
											<TD width="50%" class=NArialL valign="top" align="left">
												<select size="1" name="product" class="txfield" <%--onchange="selectBaseProduct();"--%> >
													<option value="0">All Products</option>
													<logic:iterate id="baseProductSelectList" name="baseProductList">
														<logic:equal name="baseProductSelectList" property="value" value="<%=baseProductId%>"><option value="<bean:write name="baseProductSelectList" property="value"/>" selected><bean:write name="baseProductSelectList" property="label"/></option></logic:equal>
														<logic:notEqual name="baseProductSelectList" property="value" value="<%=baseProductId%>"><option value="<bean:write name="baseProductSelectList" property="value"/>"><bean:write name="baseProductSelectList" property="label"/></option></logic:notEqual>
													</logic:iterate>
												</select>
											</TD>
										   <%-- <TD width="20%" valign="top" class=NArialL>Product <br> (Mfg Part Number)</TD>
											<TD width="25%" class=NArialL valign="top" >
												<select name="mfgproducts" class="txfield"  >
													<option value="0">All Products</option>
													<logic:iterate id="fgproductSelectList" name="fgproductSelectList">
														<logic:notEqual name="fgproductSelectList" value="null"><option value="<bean:write name="fgproductSelectList" property="productId"/>"><bean:write name="fgproductSelectList" property="manufacturingPartNo"/></option></logic:notEqual>
													</logic:iterate>
												</select>
											</TD>
											<TD width="5%" valign="top" class=NArialL>&nbsp;</TD>            --%>
										</TR>
										<TR><TD colSpan="6"><IMG height=8 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD></TR>
									   <%-- <TR>
											<TD>&nbsp;</TD>
											<TD class=NArialL>Customer</TD>
											<TD class=NArialL>
												 <select name="customers" class="txfield">
													<option value="0">All Customers</option>
													<logic:iterate id="customerSelectList" name="customerSelectList">
															<logic:equal name="customerSelectList" property="customerId" value="<%=customerId%>"><option value="<bean:write name="customerSelectList" property="customerId"/>" selected><bean:write name="customerSelectList" property="customerName"/></option></logic:equal>
															<logic:notEqual name="customerSelectList" property="customerId" value="<%=customerId%>"><option value="<bean:write name="customerSelectList" property="customerId"/>"><bean:write name="customerSelectList" property="customerName"/></option></logic:notEqual>
													</logic:iterate>
												</select>
											</TD>
											<TD>&nbsp;</TD>
											<TD>&nbsp;</TD>
											<TD>&nbsp;</TD>
										</TR>
										<TR><TD colSpan="6"><IMG height=8 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD></TR>
										<TR>
											<TD>&nbsp;</TD>
											<TD class=NArialL><bean:message key="label.sales.endCustomer"/></TD>
											<TD class=NArialL>
												<select name="enduser" class="txfield"  >
													<option value="0">All <bean:message key="label.sales.endCustomer"/>s</option>
													<logic:iterate id="endUserList" name="endUsersWithEndUserIds">
														<option value="<bean:write name="endUserList" property="value"/>" selected><bean:write name="endUserList" property="label"/></option>
													</logic:iterate>
												</select>
											</TD>
											<TD>&nbsp; </TD>
											<TD>&nbsp; </TD>
											<TD>&nbsp;</TD>
										</TR> --%>
										<TR><TD colSpan="6"><IMG height=8 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD></TR>
										<TR>
                                            <TD>&nbsp;</TD>
											<TD class=NArialL width="20%">
												<input type="radio"  name="holdtype" value="WITHHOLD" <%=hold[0]%>>&nbsp;&nbsp;With Hold
											</TD>
											<TD class="NArialL" colspan="2" width="55%"><input type="radio" name="holdtype" value="WITHOUTHOLD" <%=hold[1]%>>&nbsp;&nbsp;Without Hold</TD>
											<TD>&nbsp;</TD>
										</TR>
										<TR><TD colSpan="6"><IMG height=8 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD></TR>
									   <%-- <TR>
											<TD>&nbsp;</TD>
											<TD class=NArialL>&nbsp;</TD>
											<TD class=NArialL>
												<input type="radio"  name="detailorsummary" value="byMonth" onclick="disableProductDropDownBox();" <%=group[0]%>>&nbsp;&nbsp;By Detail
											</TD>
											<TD class="NArialL" colspan="2"><input type="radio" name="detailorsummary" value="byQuarter" onclick="disableProductDropDownBox();" <%=group[1]%>>&nbsp;&nbsp;By Summary</TD>
											<TD>&nbsp;</TD>
										</TR>
										<TR><TD colSpan="6"><IMG height=8 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD></TR> --%>
										<TR>
											  <TD>&nbsp;</TD>

											<TD class=NArialL width="20%">
												<input type="radio" name="category" value="REQUESTED" <%=category[0]%>>&nbsp;&nbsp;By Requested Date
											</TD>
											<TD class="NArialL" colspan="2" width="55%">
												<input type="radio" name="category" value="SCHEDULE" <%=category[1]%>>&nbsp;&nbsp;By Schedule Date
											</TD>
											<TD>&nbsp;</TD>
										</TR>
									</TABLE>
								</TD>
							</TR>
							<TR><TD colSpan="6">&nbsp;</TD></TR>
							<tr><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>&nbsp;</td></tr>
							<tr>
								<td width="30%" colspan="2"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>&nbsp;</td>
								<td width="70%"  colspan="4" align="left">
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									<input type="image" onClick="javascript:return submitAgedBacklogForm();"  border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Generate Report';return true"onmouseout="window.status='';return true"title="Click here to Generate Report">
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									<a href="javascript:document.agedBacklogForm.reset();"><img src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border='0' onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"title="Click here to Reset"></a>
								</td>
							</tr>
						</table>
						<BR><BR><BR>
						</form>
					</TD>
					<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
				</TR>
			</TABLE>
	<!-- Footer starts here -->
	<%@ include file="/jsp/includes/footer.jsp" %>
	<!-- footer end here -->
</BODY>
</HTML>